﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FortuneHeaven.BLL.Accounts;
using Jzy.Core.Common.Web;
using Jzy.Core.Common;
using Jzy.Common;
using Jzy.Core.Common.Basic;
using FortuneHeaven.Entity.Accounts;
using FortuneHeaven.BLL.NetBar;
using FortuneHeaven.Entity.NetBar;

namespace FortuneHeaven.Admin.Pages.Accounts
{
    public partial class AddList : PageList
    {
        private string Accounts
        {
            get
            {
                return Request.QueryString["Accounts"];
            }
        }

        private ScoreHistoryBO ScoreHistory
        {
            get
            {
                return ScoreHistoryBO.Instance<ScoreHistoryBO>();
            }
        }

        private int? _netBarID;
        private int NetBarID
        {
            get
            {
                if (_netBarID == null)
                {
                    UserExBO user = new UserExBO();
                    UserExInfo info = user.GetInfo(AppSession.UserID);
                    if (info != null)
                    {
                        _netBarID = info.NetBarID;
                    }
                    else
                    {
                        _netBarID = 0;
                    }
                }
                return _netBarID.Value;
            }
        }
        

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtName.Text = Accounts;

                BindView();
            }
        }

        private void BindView()
        {
            LVUtil.Init(lv, lvHeader);
            PagerSetting setting = new PagerSetting();
            setting.PageIndex = this.PageIndex;
            setting.PageSize = AppConfig.PageSize;
            setting.OrderBy = "InputTime desc";

            setting.Where = "NetBarID=@p0";

            int accountID = 0;
            if (txtName.Text.Trim() != "")
            {
                AccountsBO accounts = new AccountsBO();
                AccountsInfo accInfo = accounts.GetInfobyAccount(txtName.Text.Trim());
                if (accInfo != null)
                {
                    accountID = accInfo.UserID;
                }

                setting.Where += " and AccountID = @p1 ";
            }

            string prefix = GlobalVar.WebCurrPath + "AddList.aspx?Name=" + txtName.Text.Trim();
            List<ScoreHistoryInfo> list = this.ScoreHistory.GetList(setting, NetBarID,  accountID );
            lv.DataKeyNames = new string[] { "ID" };
            lv.DataSource = list;
            lv.DataBind();

            litPager.Text = HtmlPager.Render(setting, prefix, true);

        }

        protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindView();
        }
    }
}